#include <iostream>
#include <ctime>
#include <fstream>

using namespace std;

void bubblesort(int list[], int listlength)
{
    while(listlength--)
    {
        bool swapped = false;
        for (int i=0; i<listlength; i++)
        {
            if (list[i]>list[i+1])
            {
                swap(list[i], list[i+1]);
                swapped = true;
            }

        }
        if (swapped==false) break;
    }
}

void read_from_file(const char *filename, int a[], int length)
{
    ifstream file(filename);
    for (int i = 0; i<length; i++)
        file>>a[i];
}

int main()
{
    const int LEN = 5000;
    int a[LEN];
    read_from_file("m1_sorted.txt", a, LEN);
    unsigned int t_start = clock();
    bubblesort(a, LEN);
    unsigned int t_finish = clock();
    unsigned int t_work = t_finish - t_start;
    cout<<"m1_sorted "<<t_work<<" milliseconds"<<endl;
    read_from_file("m2_reverse.txt", a, LEN);
    unsigned int t_start1 = clock();
    bubblesort(a, LEN);
    unsigned int t_finish1 = clock();
    unsigned int t_work1 = t_finish1-t_start1;
    cout<<"m2_reverse "<<t_work1<<" milliseconds"<<endl;
    read_from_file("m3_shuffle.txt", a, LEN);
    unsigned int t_start2 = clock();
    bubblesort(a, LEN);
    unsigned int t_finish2 = clock();
    unsigned int t_work2 = t_finish2-t_start2;
    cout<<"m3_shuffle "<<t_work2<<" milliseconds"<<endl;



}
